﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RehabilitationRobot
{
    public static class UIThread
    {
        /* 读取滑动条的值 */
        public static int ReadTrackBarValue(TrackBar controll)
        {
            if (controll.InvokeRequired)
            {
                Func<int> action = () => { return controll.Value; };
                return (int)controll.Invoke(action);
            }
            else
                return controll.Value;
        }       

        /* 多选一按钮 */
        public static int TrainModeSelect(RadioButton x,RadioButton y,RadioButton z)
        {
            if (x.Checked) return 0;
            if (y.Checked) return 1;
            if (z.Checked) return 2;
            else return -1;
        }

        /* 控件文本值改变 */
        public static void ChangeText(Control control, string text)
        {
            if (control.InvokeRequired)
            {
                Action<string> action = x => { control.Text = x.Trim(); };
                control.Invoke(action, text);
            }
            else
            {
                control.Text = text.Trim();
            }
        }

        /* 控件可用属性改变 */
        public static void ChangeEnable(Control control,bool isEnable)
        {
            if(control.InvokeRequired)
            {
                Action<bool> action = (x) => { control.Enabled = x; };
                control.Invoke(action, isEnable);
            }
            else
            {
                control.Enabled = isEnable;
            }
        }
    }
}
